<?php
/**
 * 親善チームマッパークラスモジュール
 */
require_once APPLICATION_PATH . '/models/TeamFriend/xml/Controller.php';
require_once 'Request/Request.php';

/**
 * 親善チームコンポーネントデータマッパ
 * Enter description here ...
 * @author shinichi
 *
 */
class Components_TeamFriend_Mapper extends Models_TeamFrien_Xml_Controller
{
	/** @var $_objRequest HTTPリクエストオブジェクト	 */
	protected $_objRequest;

	/**
	 * コンストラクタ
	 * Enter description here ...
	 */
	public function __construct()
	{
		$this->_objRequest = new Lib_Request();
	}

	/**
	 * 追加
	 * (non-PHPdoc)
	 * @see Models_TeamFriend_Controller::add()
	 */
	public function add()
	{
		/***
		 * バリデーション
		 */
		$this->_objRequest->clearValidKeyList();
		$this->_objRequest->ValidRequireList[] = self::KEY_NAME;
		$this->_objRequest->ValidRequireList[] = self::KEY_DELEGATE;
		$this->_objRequest->ValidRequireList[] = self::KEY_TEL;
		$this->_objRequest->ValidRequireList[] = self::KEY_EMAIL;
		if ( !$this->_objRequest->valid() ) {
			return FALSE;
		}

		$sName = $this->_objRequest->get(self::KEY_NAME);
		$sDelegate = $this->_objRequest->get(self::KEY_DELEGATE);
		$sTel = $this->_objRequest->get(self::KEY_TEL);
		$sEMAIL = $this->_objRequest->get(self::KEY_EMAIL);
		parent::add($sName, $sDelegate, $sTel, $sEMAIL);
		return TRUE;
	}

	/**
	 * 削除
	 * (non-PHPdoc)
	 * @see Models_Controller::delelte()
	 */
	public function delelte()
	{
		/***
		 * バリデーション
		 */
		$this->_objRequest->clearValidKeyList();
		$this->_objRequest->ValidRequireList[] = self::KEY_ID;
		if ( !$this->_objRequest->valid() ) {
			return FALSE;
		}

		$sId = $this->_objRequest->get(self::KEY_ID);
		$bResult = parent::delelte($sId);
		return $bResult;
	}

	public function update()
	{
		/**
		 * バリデーション
		 */
		$this->_objRequest->clearValidKeyList();
		$this->_objRequest->ValidRequireList[] = self::KEY_ID;
		$this->_objRequest->ValidRequireList[] = self::KEY_NAME;
		$this->_objRequest->ValidRequireList[] = self::KEY_DELEGATE;
		$this->_objRequest->ValidRequireList[] = self::KEY_DELEGATE;
		$this->_objRequest->ValidRequireList[] = self::KEY_TEL;
		$this->_objRequest->ValidRequireList[] = self::KEY_EMAIL;
		if ( !$this->_objRequest->valid()  ) {
			return FALSE;
		}

		$sId = $this->_objRequest->get(self::KEY_ID);
		$sName = $this->_objRequest->get(self::KEY_NAME);
		$sDelegate = $this->_objRequest->get(self::KEY_DELEGATE);
		$sTel = $this->_objRequest->get(self::KEY_TEL);
		$sEMAIL = $this->_objRequest->get(self::KEY_EMAIL);
		parent::update($sId, $sName, $sDelegate, $sTel, $sEMAIL);
		return TRUE;
	}
}